summaryrefslogtreecommitdiffstats
path: root/src/video_core/renderer_opengl/present/util.h
blob: 67f03aa2753e8271a54511aa3604fc8866abeeaa (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
// SPDX-FileCopyrightText: Copyright 2024 yuzu Emulator Project
// SPDX-License-Identifier: GPL-2.0-or-later

#pragma once

#include <string>

#include "common/assert.h"
#include "video_core/renderer_opengl/gl_resource_manager.h"

namespace OpenGL {

static inline void ReplaceInclude(std::string& shader_source, std::string_view include_name,
                                  std::string_view include_content) {
    const std::string include_string = fmt::format("#include \"{}\"", include_name);
    const std::size_t pos = shader_source.find(include_string);
    ASSERT(pos != std::string::npos);
    shader_source.replace(pos, include_string.size(), include_content);
};

static inline OGLSampler CreateBilinearSampler() {
    OGLSampler sampler;
    sampler.Create();
    glSamplerParameteri(sampler.handle, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
    glSamplerParameteri(sampler.handle, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
    glSamplerParameteri(sampler.handle, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
    glSamplerParameteri(sampler.handle, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
    glSamplerParameteri(sampler.handle, GL_TEXTURE_WRAP_R, GL_CLAMP_TO_EDGE);
    return sampler;
}

static inline OGLSampler CreateNearestNeighborSampler() {
    OGLSampler sampler;
    sampler.Create();
    glSamplerParameteri(sampler.handle, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
    glSamplerParameteri(sampler.handle, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
    glSamplerParameteri(sampler.handle, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
    glSamplerParameteri(sampler.handle, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
    glSamplerParameteri(sampler.handle, GL_TEXTURE_WRAP_R, GL_CLAMP_TO_EDGE);
    return sampler;
}

} // namespace OpenGL